function o(e, t, n) {
    return t in e ? Object.defineProperty(e, t, {
        value: n,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = n, e;
}

var i = require("../Comm/ChatResConfig.js"), a = require("../Comm/ChatBubbleConfig.js"),
    r = require("../UIManager/UISoundManager.js");
cc.Class({
    extends: cc.Component,
    properties: {
        Node_Seats: {
            default: null,
            type: cc.Node
        },
        interactionAniPre: {
            default: null,
            type: cc.Prefab
        },
        chatBubblePre: {
            default: null,
            type: cc.Prefab
        }
    },
    onLoad: function () {
        Global.notificationCenter.on(Global.eventName.GAME_SET_INTERATIONBAR, this.setInteractionBar.bind(this), this),
            Global.notificationCenter.on(Global.eventName.GAME_DES_INTERATIONBAR, this.onInteractionBarClickOther.bind(this), this),
            Global.notificationCenter.on(Global.eventName.GAME_TABLE_CHAT, this.onInterations.bind(this), this),
            this.interactionBar = null, this.seats = this.Node_Seats.children;
    },
    start: function () {
    },
    getInteractionBar: function () {
        return this.interactionBar;
    },
    setInteractionBar: function (e) {
        this.interactionBar = e;
    },
    getChatRes: function (e) {
        e = parseInt(e);
        var t = 16 * Math.floor(e / 16), n = Math.floor(e % 16);
        return t == i.CHATSTATIC.EMOTION ? {
            type: "表情",
            res: i.EMOTIONRES[n],
            index: n
        } : t == i.CHATSTATIC.STATICTXT ? {
            type: "文本",
            res: i.STATIC_TXT[n],
            sound: i.TXT_SOUND[n],
            index: n
        } : t == i.CHATSTATIC.INTERRACT ? {
            type: "互动",
            res: i.INTERACT_EMOTION[n],
            sound: i.INTERACT_SOUND[n],
            index: n
        } : {};
    },
    onInterations: function (e) {
        console.log("-------------onInterations-------------");
        var t, n = e.msg, s = Global.tableModel;
        if (t = "string" == typeof e.msg ? this.getChatRes(e.msg) : this.getChatRes(e.msg.emoId),
            console.log("onInterations === ", t), "互动" == t.type) {
            var l, c = t.index, d = s.toLocalSeatIndex(n.resourceSeatId), u = this.seats[d],
                h = s.toLocalSeatIndex(n.targetSeatId), f = this.seats[h], p = t.res, g = function () {
                    var e = cc.instantiate(this.interactionAniPre);
                    e && f && f.getComponent("GameHeadController").playInteractionAni(e, c, t.sound);
                }.bind(this);
            Global.utils.itemFly((o(l = {
                startNode: u,
                endNode: f,
                duration: .7,
                spriteFrame: p,
                isSpeedEase: !0,
                isDirection: !0
            }, "isSpeedEase", !0), o(l, "directionX", 1), o(l, "referAngle", Math.PI / 6), o(l, "isBezierEase", !0),
                o(l, "callback", g), l));
        } else if ("文本" == t.type) {
            var b = e.userId, m = 0;
            (G = s.getPlayerModelByUserId(b)) && (m = s.toLocalSeatIndex(G.getSeatId()));
            var _ = Global.userProfile.getUserSex(), y = (c = t.index, t.res), S = "m";
            _ && (S = "w");
            var I = cc.instantiate(this.chatBubblePre);
            this.seats[m] && this.seats[m].addChild(I);
            var v = Global.utils.searchNode(I, "chatInfo").getComponent(cc.Label);
            v.string = y, a.initChatBubble(I, m);
            var C = this;
            g = function () {
                if (!(null == C.seats || C.seats.length <= 0)) {
                    var e = C.seats[m];
                    null != e && cc.isValid(e) && e.removeChild(I);
                }
            };
            v.scheduleOnce(function () {
                g && g();
            }, 1.6), r.playSCMJChat(_, t.sound + S);
        } else if ("表情" == t.type) {
            var G;
            b = e.userId, m = 0;
            (G = s.getPlayerModelByUserId(b)) && (m = s.toLocalSeatIndex(G.getSeatId()));
            c = t.index;
            var T = new cc.Node();
            T.name = "_item", Global.spriteAtlas.setSpriteFrame(T.addComponent(cc.Sprite), "Texture/chat_emotion", i.EMOTION[c]),
                cc.loader.loadRes("anim/common/jellyAni", cc.AnimationClip, function (e, t) {
                    if (e) cc.error(e.message || e); else {
                        cc.log("Result should be a clip: " + (t instanceof cc.AnimationClip));
                        var n = T.addComponent(cc.Animation);
                        this.seats && this.seats[m] && this.seats[m].addChild(T), n.addClip(t);
                        var o = 0;
                        n.on("finished", function () {
                            ++o >= 2 ? T.destroy() : n.play("jellyAni");
                        }, this), n.play("jellyAni");
                    }
                }.bind(this));
        }
    },
    onInteractionBarClickOther: function () {
        this.interactionBar && (this.interactionBar.destroy(), this.interactionBar = null);
    },
    onDestroy: function () {
        Global.notificationCenter.offAll(this);
    }
})
